provider "alicloud" {
  region                = local.region
}

terraform {
  required_version      = ">= 0.12"  
  backend "oss" {
    bucket              = "terraform-resources"
    key                 = "prod/services/nexus-cdn"
    tablestore_endpoint = "https://terraform-state.cn-shenzhen.ots.aliyuncs.com"
    tablestore_table    = "terraform_statelock_table"    
    region              = "cn-shenzhen"
  }
}

module "cdn" {
  source                      = "../../../modules/alicloud/cdn/domain"
  cdn_domain_name             = "proxy-apt.deeproute.ai"
  cdn_type                    = "download"  //type: download、web、video
  cdn_scope                   = "overseas"
  tags                        = local.tags
  cdn_sources                 = [
    {
      content                 = "apt-sz.deeproute.cn"
      type                    = "domain" //oss、ipaddr、domain
      port                    = "443"
      priority                = "20"
      weight                  = "10"
    }
  ]
  cdn_certificate_config        = [
    {
      server_certificate_status = "on"
      cert_type                 = "cas" //or free、cas、upload
      cert_name                 = "*.deeproute.ai"
      server_certificate        = ""
      private_key               = ""
      force_set                 = "0" //domain verify  issues: https://github.com/aliyun/terraform-provider-alicloud/issues/3229
    }
  ]
}
# module "cdn_forward_scheme_config" {
#   source                      = "../../../modules/cdn/domain-config"  
#   cdn_domain_name             = module.cdn.domain_name
#   cdn_function_name           = "forward_scheme" //静态协议跟随回源
#   cdn_function_args           = [
#     {
#       arg_name                = "enable"
#       arg_value               = "on"
#     },    
#     {
#       arg_name                = "scheme_origin"
#       arg_value               = "http"
#     },
#   ]  
# }
# # module "cdn_priveate_oss_config" { //开启会少了临时访问token
# #   source                      = "../../../modules/cdn/domain-config"  
# #   cdn_domain_name             = module.cdn.domain_name
# #   cdn_function_name           = "l2_oss_key" //私有buckct回源
# #   cdn_function_args           = [
# #     {
# #       arg_name                = "private_oss_auth"
# #       arg_value               = "on"
# #     },
# #   ]  
# # }
# module "cdn_file_ttl_config" {
#   source                      = "../../../modules/cdn/domain-config"  
#   cdn_domain_name             = module.cdn.domain_name
#   cdn_function_name           = "filetype_based_ttl_set" //文件过期时间设置
#   cdn_function_args           = [
#     {
#       arg_name                = "file_type"
#       arg_value               = "jss,css"
#     },
#     {
#       arg_name                = "ttl"
#       arg_value               = "86400"
#     },  
#     {
#       arg_name                = "weight"
#       arg_value               = "99"
#     },     
#   ]  
# }
# module "cdn_file_ttl_code_config" {
#   source                      = "../../../modules/cdn/domain-config"  
#   cdn_domain_name             = module.cdn.domain_name
#   cdn_function_name           = "filetype_force_ttl_code" //文件状态码过期时间设置
#   cdn_function_args           = [
#     {
#       arg_name                = "file_type"
#       arg_value               = "js,css"
#     },
#     {
#       arg_name                = "code_string"
#       arg_value               = "403=30,404=30,500=30,502=30,503=30,504=30"
#     },       
#   ]  
# }
# # module "cdn_https_option_config" { //和cert有冲突,默认即开启
# #   source                      = "../../../modules/cdn/domain-config"  
# #   cdn_domain_name             = module.cdn.domain_name
# #   cdn_function_name           = "https_option" 
# #   cdn_function_args           = [   
# #     {
# #       arg_name                = "http2"
# #       arg_value               = "on"
# #     },    
# #   ]  
# # }
# module "cdn_https_force_config" {
#   source                      = "../../../modules/cdn/domain-config"  
#   cdn_domain_name             = module.cdn.domain_name
#   cdn_function_name           = "https_force" 
#   cdn_function_args           = [
#     {
#       arg_name                = "enable"
#       arg_value               = "on"
#     },    
#   ]  
# }
# module "cdn_HSTS_config" {
#   source                      = "../../../modules/cdn/domain-config"  
#   cdn_domain_name             = module.cdn.domain_name
#   cdn_function_name           = "HSTS"  //防第一次建立连接被劫持
#   cdn_function_args           = [
#     {
#       arg_name                = "enabled"
#       arg_value               = "on"
#     }, 
#     {
#       arg_name                = "https_hsts_max_age"
#       arg_value               = "5184000"
#     },           
#   ]  
# }
# module "cdn_set_hashkey_config" {
#   source                      = "../../../modules/cdn/domain-config"  
#   cdn_domain_name             = module.cdn.domain_name
#   cdn_function_name           = "set_hashkey_args"  //回源时会去除 URL 中？之后的参数
#   cdn_function_args           = [
#     {
#       arg_name                = "disable"
#       arg_value               = "on"
#     },           
#   ]  
# }